package com.bkd.dreams.server.stand;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManager;

import com.bkd.dreams.client.login.NotLoggedInException;
import com.bkd.dreams.client.stand.StandRole;
import com.bkd.dreams.client.stand.service.StandRoleService;
import com.bkd.dreams.server.PMF;
import com.bkd.dreams.server.core.RemoteServiceImpl;

public class StandRoleServiceImpl extends RemoteServiceImpl implements StandRoleService {

	@Override
	public List<StandRole> getAllStandRoles() throws NotLoggedInException {
		checkLoggedIn();
		List<StandRole> roles = new ArrayList<StandRole>();
		PersistenceManager pm = PMF.get().getPersistenceManager();
		try {
			List<StandRole> queryResults = (List<StandRole>)pm.newQuery("select from " + StandRole.class.getName()).execute();
			roles.addAll(queryResults);
		} finally {
			pm.close();
		}
		return roles;
	}

	@Override
	public void addStandRole(StandRole role) throws NotLoggedInException {
		store(role);
	}

	@Override
	public void removeStandRole(StandRole role) throws NotLoggedInException {
		removeByKey(role.getKey());
	}

}
